In [1]:
from util import *
from glob import glob
import matplotlib.pyplot as plt
from shapely import wkt
In [2]:
df = load_AOIs()
df
Out[2]:
| Taranaki | AOI | SSP 4.5 (p50) | SSP 4.5 (p83) | SSP 8.5 (p50) | SSP 8.5 (p83) | Rate SSP 4.5 (p50) | Rate SSP 4.5 (p83) | Rate SSP 8.5 (p50) | Rate SSP 8.5 (p83) | match | match_score | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7 | NORTH | TongaporutuRiver | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | TongapurutuRiverCliffs | 93.750000 |
| 11 | SOUTH | HangatahuaRiver_South | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | HangatahuRiver_South | 97.435897 |
| 21 | SOUTH | Rahotu | 0.58 | 0.78 | 0.84 | 1.10 | 0.0058 | 0.0078 | 0.0084 | 0.0110 | Rahotu | 100.000000 |
| 20 | SOUTH | Pihama | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | Pihama | 100.000000 |
| 19 | SOUTH | OpunakeBeach | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | OpunakeBeachCliffs | 100.000000 |
| 18 | SOUTH | OhaweBeach | 0.57 | 0.78 | 0.83 | 1.10 | 0.0057 | 0.0078 | 0.0083 | 0.0110 | OhaweBeach | 100.000000 |
| 17 | SOUTH | Oeo | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | Oeo | 100.000000 |
| 16 | SOUTH | Manutahi | 0.57 | 0.78 | 0.83 | 1.10 | 0.0057 | 0.0078 | 0.0083 | 0.0110 | Manutahi | 100.000000 |
| 15 | SOUTH | ManaBay | 0.57 | 0.78 | 0.83 | 1.10 | 0.0057 | 0.0078 | 0.0083 | 0.0110 | ManaBayCliffs | 100.000000 |
| 14 | SOUTH | KaupokonuiBeach | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | KaupokonuiBeach | 100.000000 |
| 13 | SOUTH | Kakaramea | 0.57 | 0.78 | 0.83 | 1.10 | 0.0057 | 0.0078 | 0.0083 | 0.0110 | Kakaramea | 100.000000 |
| 12 | SOUTH | Hawera_WaihiBeach | 0.57 | 0.78 | 0.83 | 1.10 | 0.0057 | 0.0078 | 0.0083 | 0.0110 | Hawera_WaihiBeach | 100.000000 |
| 0 | NORTH | Mohakatino_River | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | MohakatinoRiver | 100.000000 |
| 10 | SOUTH | CapeEgmont | 0.58 | 0.78 | 0.84 | 1.10 | 0.0058 | 0.0078 | 0.0084 | 0.0110 | CapeEgmont | 100.000000 |
| 9 | NORTH | Waitara | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | Waitara | 100.000000 |
| 8 | NORTH | UrenuiRiver_North | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | UrenuiRiverNorthCliffs | 100.000000 |
| 6 | NORTH | PariokariwaPoint | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | PariokariwaPointCliffs | 100.000000 |
| 5 | NORTH | Onaero | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | OnaeroCliff | 100.000000 |
| 4 | NORTH | Oakura_South | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | OakuraSouth | 100.000000 |
| 3 | NORTH | Oakura | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | Oakura | 100.000000 |
| 2 | NORTH | NewPlymouth_Airport | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | NewPlymouthAirport | 100.000000 |
| 1 | NORTH | NewPlymouth | 0.57 | 0.78 | 0.84 | 1.10 | 0.0057 | 0.0078 | 0.0084 | 0.0110 | NewPlymouthCliffs | 100.000000 |
| 22 | SOUTH | WainuiBeach | 0.57 | 0.78 | 0.83 | 1.09 | 0.0057 | 0.0078 | 0.0083 | 0.0109 | WainuiBeach | 100.000000 |
| 23 | SOUTH | WaipipiBeach | 0.57 | 0.78 | 0.83 | 1.09 | 0.0057 | 0.0078 | 0.0083 | 0.0109 | WaipipiBeachCliffs | 100.000000 |
In [3]:
site = df.match.sample(1).iloc[0]
site = "Oeo"
site
Out[3]:
'Oeo'
In [4]:
gdf = gpd.read_file(f"Shapefiles/{site}_intersects.shp")
gdf.crs = 2193
gdf = enrich_df(gdf)
transect_metadata = get_transect_metadata(f"Shapefiles/{site}_TransectLines.shp")
if site == "ManaBayCliffs":
print("Flipping")
for k, v in transect_metadata.items():
transect_metadata[k]["Azimuth"] = v["Azimuth"] + 180
In [5]:
group_data = gdf[gdf.TransectID == 436]
group_data
Out[5]:
| OBJECTID | TransectID | TransOrder | BaselineID | ShorelineI | Distance | IntersectX | IntersectY | Uncertaint | AOI | geometry | Date | Year | YearsSinceBase | YearsUntilFuture | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1337 | 1624 | 436 | 436 | 1 | 31/10/2016 | 15.368598 | 1.684813e+06 | 5.621396e+06 | 2.091626 | Oeo | POINT (1684812.590 5621396.412) | 2016-10-31 | 2016 | 76.832307 | 83.167693 |
| 1338 | 1625 | 436 | 436 | 1 | 18/03/2022 | 8.864836 | 1.684819e+06 | 5.621399e+06 | 2.429774 | Oeo | POINT (1684818.570 5621398.970) | 2022-03-18 | 2022 | 82.209446 | 77.790554 |
In [6]:
linear_model = LinearRegression().fit(
group_data.YearsSinceBase.to_numpy().reshape(-1, 1), group_data.Distance
)
In [7]:
linear_model.coef_[0], linear_model.intercept_
Out[7]:
(-1.2095208005543252, 108.29887058148721)
In [8]:
linear_model.score(group_data.YearsSinceBase.to_numpy().reshape(-1, 1), group_data.Distance)
Out[8]:
1.0
In [9]:
linear_model.coef_[0] * 160 + linear_model.intercept_
Out[9]:
-85.22445750720483
In [10]:
linear_model.predict([[160]])
Out[10]:
array([-85.22445751])
In [11]:
ax = group_data.plot(x="YearsSinceBase", y="Distance", kind="scatter")
years_to_predict = np.array([0] + group_data.YearsSinceBase.tolist() + [160])
print(years_to_predict)
ax.plot(
years_to_predict,
linear_model.predict(years_to_predict.reshape(-1, 1)),
color="red",
)
[ 0. 76.83230664 82.20944559 160. ]
Out[11]:
[<matplotlib.lines.Line2D at 0x7f859409eef0>]
In [12]:
latest_row = group_data[group_data.Date == group_data["Date"].max()].iloc[0]
latest_row
Out[12]:
OBJECTID 1625 TransectID 436 TransOrder 436 BaselineID 1 ShorelineI 18/03/2022 Distance 8.864836 IntersectX 1684818.57004 IntersectY 5621398.96952 Uncertaint 2.429774 AOI Oeo geometry POINT (1684818.5700383317 5621398.969516366) Date 2022-03-18 Year 2022 YearsSinceBase 82.209446 YearsUntilFuture 77.790554 Name: 1338, dtype: object
In [13]:
pred = linear_model.predict([[latest_row.YearsSinceBase]])[0]
print(f"Linear model predicts {round(latest_row.Distance - pred)}m erosion")
Linear model predicts 0m erosion
In [14]:
linear_models = fit(gdf, transect_metadata)
linear_models.loc[linear_models.slope > 0, "slope"] = pd.NA
rolled_slopes = linear_models.groupby("group").slope.rolling(10, min_periods=1).mean().dropna().reset_index(level=0)
linear_models.slope = rolled_slopes.slope
linear_models.dropna(inplace=True)
linear_models
Out[14]:
| TransectID | slope | intercept | group | r2_score | mae | mse | rmse | |
|---|---|---|---|---|---|---|---|---|
| 0 | 2 | -0.025895 | 11.839523 | 0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 1 | 3 | -0.026103 | 11.394666 | 0 | 1.000000 | 1.776357e-15 | 3.155444e-30 | 1.776357e-15 |
| 2 | 4 | -0.032111 | 12.067457 | 0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 3 | 5 | -0.037306 | 12.952147 | 0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 4 | 6 | -0.041094 | 14.552892 | 0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 665 | 806 | -0.088458 | 17.144344 | 50 | 0.462361 | 2.814825e+00 | 9.597485e+00 | 3.097981e+00 |
| 666 | 807 | -0.098385 | 17.888823 | 50 | 0.439388 | 3.502577e+00 | 1.287081e+01 | 3.587592e+00 |
| 667 | 808 | -0.100127 | 16.604210 | 50 | 0.510860 | 1.851194e+00 | 6.213661e+00 | 2.492722e+00 |
| 668 | 809 | -0.105771 | 5.736368 | 50 | 0.130797 | 1.977019e+00 | 5.294052e+00 | 2.300881e+00 |
| 669 | 810 | -0.105771 | 4.466733 | 50 | 0.167198 | 1.881087e+00 | 4.792745e+00 | 2.189234e+00 |
657 rows × 8 columns
In [15]:
results = predict(gdf, linear_models, transect_metadata)
results
Out[15]:
| TransectID | slope | intercept | group | r2_score | mae | mse | rmse | BaselineID | Year | ... | linear_model_distance | sqrt_model_point | sqrt_model_predicted_distance | sqrt_model_distance | BH_model_point | BH_model_predicted_distance | BH_model_distance | Sunamura_model_point | Sunamura_model_predicted_distance | Sunamura_model_distance | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2.0 | -0.025895 | 11.839523 | 0.0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 1 | 2100 | ... | 2.014361 | POINT (1688035.5534006841 5620798.3280850835) | 2.575163 | 7.135573 | POINT (1688043.1672309272 5620827.768582187) | -27.833936 | 37.544672 | POINT (1688037.0176938204 5620803.9900865285) | -3.273120 | 12.983856 |
| 1 | 3.0 | -0.026103 | 11.394666 | 0.0 | 1.000000 | 1.776357e-15 | 3.155444e-30 | 1.776357e-15 | 1 | 2100 | ... | 2.013439 | POINT (1688045.4118067573 5620796.610869867) | 2.055679 | 7.175904 | POINT (1688053.2101313008 5620825.9603533875) | -28.312167 | 37.543750 | POINT (1688046.9030184844 5620802.223138728) | -3.751323 | 12.982906 |
| 2 | 4.0 | -0.032111 | 12.067457 | 0.0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 1 | 2100 | ... | 1.510104 | POINT (1688055.3321562614 5620795.049295843) | 0.578900 | 7.860823 | POINT (1688062.928654537 5620823.222719841) | -28.600693 | 37.040415 | POINT (1688056.5343737882 5620799.508006012) | -4.039046 | 12.478768 |
| 3 | 5.0 | -0.037306 | 12.952147 | 0.0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 1 | 2100 | ... | 1.620997 | POINT (1688065.1311122181 5620792.999345171) | -0.394737 | 8.998973 | POINT (1688072.6592310544 5620820.126478494) | -28.547072 | 37.151308 | POINT (1688066.0911000874 5620796.458604978) | -3.984731 | 12.588967 |
| 4 | 6.0 | -0.041094 | 14.552892 | 0.0 | 1.000000 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 1 | 2100 | ... | 1.950942 | POINT (1688074.7352682156 5620790.222629285) | -0.149400 | 10.078169 | POINT (1688081.7768776012 5620816.705543141) | -27.552484 | 37.481253 | POINT (1688075.4651071057 5620792.967493336) | -2.989637 | 12.918406 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 652 | 806.0 | -0.088458 | 17.144344 | 50.0 | 0.462361 | 2.814825e+00 | 9.597485e+00 | 3.097981e+00 | 1 | 2100 | ... | 2.020175 | POINT (1687892.4113368606 5620820.913072934) | -14.503338 | 19.514583 | POINT (1687895.824934831 5620838.622988925) | -32.539240 | 37.550485 | POINT (1687891.1748046514 5620814.497882353) | -7.970063 | 12.981308 |
| 653 | 807.0 | -0.098385 | 17.888823 | 50.0 | 0.439388 | 3.502577e+00 | 1.287081e+01 | 3.587592e+00 | 1 | 2100 | ... | 2.435977 | POINT (1687902.105572404 5620821.720250634) | -17.310369 | 21.893612 | POINT (1687904.5866393007 5620837.600276526) | -33.383045 | 37.966288 | POINT (1687900.7938008038 5620813.324279123) | -8.812541 | 13.395784 |
| 654 | 808.0 | -0.100127 | 16.604210 | 50.0 | 0.510860 | 1.851194e+00 | 6.213661e+00 | 2.492722e+00 | 1 | 2100 | ... | 5.662195 | POINT (1687910.64721948 5620822.479462039) | -19.218452 | 25.464476 | POINT (1687911.7553046227 5620838.168409724) | -34.946482 | 41.192506 | POINT (1687910.0242252424 5620813.6587283) | -10.375745 | 16.621769 |
| 655 | 809.0 | -0.105771 | 5.736368 | 50.0 | 0.130797 | 1.977019e+00 | 5.294052e+00 | 2.300881e+00 | 1 | 2100 | ... | 17.597616 | POINT (1687920.859272824 5620834.459251945) | -32.105525 | 38.516099 | POINT (1687921.5934341024 5620849.052623445) | -46.717352 | 53.127926 | POINT (1687920.3588562713 5620824.512166921) | -22.145860 | 28.556435 |
| 656 | 810.0 | -0.105771 | 4.466733 | 50.0 | 0.167198 | 1.881087e+00 | 4.792745e+00 | 2.189234e+00 | 1 | 2100 | ... | 18.054265 | POINT (1687928.2598098365 5620836.8874109285) | -33.375160 | 38.972749 | POINT (1687927.9589022126 5620851.496139112) | -47.986986 | 53.584576 | POINT (1687928.4649134837 5620826.929858534) | -23.415495 | 29.013085 |
657 rows × 23 columns
In [16]:
pd.DataFrame(results).plot(x="TransectID", y=["linear_model_distance", "sqrt_model_distance", "BH_model_distance", "Sunamura_model_distance"], figsize=(10,10))
Out[16]:
<AxesSubplot: xlabel='TransectID'>
In [17]:
csvs = sorted(glob("Projected_Shoreline_Polygons/*.csv"))
csvs
Out[17]:
['Projected_Shoreline_Polygons/CapeEgmont_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/CapeEgmont_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/CapeEgmont_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/CapeEgmont_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/HangatahuRiver_South_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/HangatahuRiver_South_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/HangatahuRiver_South_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/HangatahuRiver_South_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Hawera_WaihiBeach_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Hawera_WaihiBeach_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Hawera_WaihiBeach_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Hawera_WaihiBeach_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Kakaramea_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Kakaramea_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Kakaramea_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Kakaramea_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/KaupokonuiBeach_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/KaupokonuiBeach_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/KaupokonuiBeach_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/KaupokonuiBeach_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/ManaBayCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/ManaBayCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/ManaBayCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/ManaBayCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Manutahi_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Manutahi_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Manutahi_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Manutahi_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/MohakatinoRiver_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/MohakatinoRiver_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/MohakatinoRiver_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/MohakatinoRiver_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthAirport_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthAirport_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthAirport_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthAirport_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/NewPlymouthCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OakuraSouth_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OakuraSouth_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OakuraSouth_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OakuraSouth_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Oakura_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Oakura_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Oakura_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Oakura_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Oeo_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Oeo_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Oeo_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Oeo_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OhaweBeach_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OhaweBeach_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OhaweBeach_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OhaweBeach_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OnaeroCliff_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OnaeroCliff_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OnaeroCliff_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OnaeroCliff_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OpunakeBeachCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OpunakeBeachCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/OpunakeBeachCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/OpunakeBeachCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/PariokariwaPointCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/PariokariwaPointCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/PariokariwaPointCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/PariokariwaPointCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Pihama_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Pihama_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Pihama_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Pihama_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Rahotu_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Rahotu_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Rahotu_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Rahotu_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/TongapurutuRiverCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/TongapurutuRiverCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/TongapurutuRiverCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/TongapurutuRiverCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/UrenuiRiverNorthCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/UrenuiRiverNorthCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/UrenuiRiverNorthCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/UrenuiRiverNorthCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/WainuiBeach_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/WainuiBeach_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/WainuiBeach_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/WainuiBeach_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/WaipipiBeachCliffs_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/WaipipiBeachCliffs_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/WaipipiBeachCliffs_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/WaipipiBeachCliffs_Rate SSP 8.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Waitara_Rate SSP 4.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Waitara_Rate SSP 4.5 (p83)_results.csv', 'Projected_Shoreline_Polygons/Waitara_Rate SSP 8.5 (p50)_results.csv', 'Projected_Shoreline_Polygons/Waitara_Rate SSP 8.5 (p83)_results.csv']
In [18]:
def read(f):
df = pd.read_csv(f)
bits = os.path.basename(f).split("_Rate ")
df["site"] = bits[0]
df["SLR"] = bits[1].replace("_results.csv", "")
return df
csv_results = pd.concat(read(f) for f in csvs)
csv_results.rename(columns={"linear_model_distance": "HistoricRate", "sqrt_model_distance": "WD", "BH_model_distance": "BH", "Sunamura_model_distance": "Sunamura"}, inplace=True)
csv_results
Out[18]:
| TransectID | slope | intercept | group | r2_score | mae | mse | rmse | original_slope | BaselineID | ... | sqrt_model_predicted_distance | WD | BH_model_point | BH_model_predicted_distance | BH | Sunamura_model_point | Sunamura_model_predicted_distance | Sunamura | site | SLR | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | -0.022164 | 10.625580 | 0.0 | 0.411895 | 0.664743 | 0.544681 | 0.738025 | -0.022164 | 1 | ... | 4.586685 | 4.013788 | POINT (1665207.8750121973 5650278.888946311) | -9.797479 | 18.397952 | POINT (1665196.4019923976 5650276.774972595) | 1.868672 | 6.731801 | CapeEgmont | SSP 4.5 (p50) |
| 1 | 2.0 | -0.022279 | 10.656445 | 0.0 | 0.398535 | 0.683677 | 0.610930 | 0.781620 | -0.022395 | 1 | ... | 4.585985 | 4.443011 | POINT (1665209.6745226474 5650269.052195227) | -9.785150 | 18.814146 | POINT (1665198.201495615 5650266.938220179) | 1.881008 | 7.147988 | CapeEgmont | SSP 4.5 (p50) |
| 2 | 3.0 | -0.021290 | 10.899940 | 0.0 | 0.273105 | 0.701507 | 0.801016 | 0.894995 | -0.019310 | 1 | ... | 5.099174 | 4.235516 | POINT (1665211.090950729 5650259.144821454) | -9.383284 | 18.717974 | POINT (1665199.617985495 5650257.030857792) | 2.282811 | 7.051879 | CapeEgmont | SSP 4.5 (p50) |
| 3 | 4.0 | -0.018583 | 11.027412 | 0.0 | 0.068164 | 0.948226 | 1.207577 | 1.098898 | -0.010462 | 1 | ... | 5.964224 | 3.606545 | POINT (1665212.3512731898 5650249.208730113) | -8.822692 | 18.393461 | POINT (1665200.878476966 5650247.094797593) | 2.843231 | 6.727538 | CapeEgmont | SSP 4.5 (p50) |
| 4 | 5.0 | -0.019135 | 12.032552 | 0.0 | 0.330090 | 0.727144 | 0.746245 | 0.863855 | -0.021344 | 1 | ... | 6.818871 | 3.052131 | POINT (1665213.2492725323 5650239.271966417) | -7.905925 | 17.776927 | POINT (1665201.794168372 5650237.063987547) | 3.760034 | 6.110968 | CapeEgmont | SSP 4.5 (p50) |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 791 | 906.0 | -0.070702 | 5.588488 | 2.0 | 0.220615 | 1.327923 | 2.968206 | 1.722848 | 0.034744 | 3 | ... | -20.941152 | 29.335741 | POINT (1703962.292991441 5683742.0238418225) | -45.695388 | 54.089977 | POINT (1703971.500439912 5683768.082676255) | -18.057733 | 26.452322 | Waitara | SSP 8.5 (p83) |
| 792 | 907.0 | -0.063472 | 5.026776 | 2.0 | 0.301152 | 1.426352 | 2.950875 | 1.717811 | 0.042744 | 3 | ... | -18.790166 | 27.062807 | POINT (1703952.0700438959 5683747.428869862) | -45.100402 | 53.373042 | POINT (1703962.1629671226 5683773.1565354485) | -17.463834 | 25.736474 | Waitara | SSP 8.5 (p83) |
| 793 | 908.0 | -0.055162 | 4.236645 | 2.0 | 0.343306 | 1.432894 | 2.601280 | 1.612848 | 0.044202 | 3 | ... | -16.462035 | 23.537088 | POINT (1703942.5813463528 5683753.249645808) | -44.560901 | 51.635954 | POINT (1703953.2815694462 5683778.729363978) | -16.925583 | 24.000636 | Waitara | SSP 8.5 (p83) |
| 794 | 909.0 | -0.045386 | 3.897024 | 2.0 | 0.313346 | 1.131100 | 1.682665 | 1.297176 | 0.033215 | 3 | ... | -13.133217 | 18.881430 | POINT (1703933.9814501503 5683759.456020689) | -43.336295 | 49.084508 | POINT (1703944.9163240474 5683784.834320479) | -15.702447 | 21.450660 | Waitara | SSP 8.5 (p83) |
| 795 | 910.0 | -0.032668 | 3.792881 | 2.0 | 0.138292 | 0.630749 | 0.702120 | 0.837926 | 0.012724 | 3 | ... | -8.465358 | 12.876748 | POINT (1703925.5960213046 5683766.343932675) | -41.405649 | 45.817040 | POINT (1703936.8261300405 5683791.590883901) | -13.773713 | 18.185104 | Waitara | SSP 8.5 (p83) |
60284 rows × 26 columns
In [19]:
most_negative = csv_results.sort_values(by="HistoricRate").iloc[0]
most_negative
Out[19]:
TransectID 101.0 slope -0.123515 intercept 29.077204 group 8.0 r2_score 0.844693 mae 2.02501 mse 5.902778 rmse 2.429563 original_slope -0.198268 BaselineID 7 Year 2100 ocean_point POINT (1721729.4107415285 5684661.107968306) linear_model_point POINT (1721980.6946175254 5684228.838585738) linear_model_predicted_distance 9.314724 HistoricRate 0.000405 sqrt_model_point POINT (1721990.3767234418 5684212.183008734) sqrt_model_predicted_distance -9.950566 WD 19.265696 BH_model_point POINT (1721993.6404886057 5684206.568538858) BH_model_predicted_distance -16.444751 BH 25.759881 Sunamura_model_point POINT (1721984.6867233445 5684221.971192792) Sunamura_model_predicted_distance 1.3713 Sunamura 7.94383 site UrenuiRiverNorthCliffs SLR SSP 4.5 (p83) Name: 69, dtype: object
In [20]:
ax = group_data.plot(x="YearsSinceBase", y="Distance", kind="scatter")
x = np.array([0, 160])
ax.plot(x, most_negative.original_slope*x + most_negative.intercept, color="red", label="original slope")
ax.plot(x, most_negative.slope*x + most_negative.intercept, color="blue", label="adjusted slope")
ax.set_title(f"{most_negative.site} Transect {most_negative.TransectID}")
ax.legend()
Out[20]:
<matplotlib.legend.Legend at 0x7f85943a71f0>
In [21]:
most_negative.slope * 82 + most_negative.intercept
Out[21]:
18.94893317378198
In [22]:
csv_results.SLR.unique()
Out[22]:
array(['SSP 4.5 (p50)', 'SSP 4.5 (p83)', 'SSP 8.5 (p50)', 'SSP 8.5 (p83)'],
dtype=object)
In [23]:
ymin, ymax = csv_results[["HistoricRate", "WD", "BH", "Sunamura"]].min().min(), csv_results[["HistoricRate", "WD", "BH", "Sunamura"]].max().max()
ymin, ymax
Out[23]:
(0.000405442195559, 575.5160150612829)
In [24]:
plt.style.use('ggplot')
for SLR in csv_results.SLR.unique():
subset = csv_results[csv_results.SLR == SLR]
ax = subset.groupby("site").boxplot(column=["HistoricRate", "WD", "BH", "Sunamura"], figsize=(20,30), showfliers=False, layout=(6,4), ylabel="meters")
plt.ylim([ymin, ymax])
plt.subplots_adjust(hspace=0.5)
plt.suptitle("Taranaki Cliff Erosion projected distance at 2100, " + SLR)
In [25]:
plt.style.use('ggplot')
for SLR in csv_results.SLR.unique():
subset = csv_results[csv_results.SLR == SLR]
grouped = subset.groupby("site")
fig, axs = plt.subplots(figsize=(20,35),
nrows=6, ncols=4,
gridspec_kw=dict(hspace=0.5))
targets = zip(grouped.groups.keys(), axs.flatten())
for i, (key, ax) in enumerate(targets):
group = grouped.get_group(key)
ax.plot(group[["HistoricRate", "WD", "BH", "Sunamura"]], label=["HistoricRate", "WD", "BH", "Sunamura"], linestyle="", marker=".")
ax.set_title(key)
ax.set_ylabel("meters")
ax.set_ylim([ymin, ymax])
#ax.legend()
plt.suptitle("Taranaki Cliff Erosion projected distance at 2100, " + SLR)
In [26]:
csv_results["lat"] = csv_results.linear_model_point.apply(lambda s: wkt.loads(s).y)
In [42]:
subset.HistoricRate.rolling(10, min_periods=1).mean()
Out[42]:
130 3.087640
129 3.265226
132 3.434248
128 3.582721
131 3.637203
...
802 10.560169
803 11.437460
804 11.280412
805 11.303683
806 11.203467
Name: HistoricRate, Length: 15071, dtype: float64
In [59]:
csv_results.sort_values("lat", inplace=True)
for SLR in csv_results.SLR.unique():
fig,ax = plt.subplots(figsize=(15,15))
subset = csv_results[csv_results.SLR == SLR]
for model in ["HistoricRate", "WD", "BH", "Sunamura"]:
ax.plot(subset[model].rolling(500).mean(), subset.lat, label=model)
ax.set_title("Taranaki Cliff Erosion projected distance at 2100, " + SLR)
ax.legend()
ax.set_xlabel("meters")
ax.set_ylabel("latitude")
ax.set_xlim(ymin, ymax)
plt.show()
In [28]:
csv_results.groupby("SLR").boxplot(column=["HistoricRate", "WD", "BH", "Sunamura"], figsize=(15,15), showfliers=False, ylabel="meters")
plt.suptitle("Taranaki Cliff Erosion projected distance at 2100")
Out[28]:
Text(0.5, 0.98, 'Taranaki Cliff Erosion projected distance at 2100')
In [29]:
csv_results[["r2_score", "mae", "mse", "rmse"]].describe()
Out[29]:
| r2_score | mae | mse | rmse | |
|---|---|---|---|---|
| count | 6.028400e+04 | 60284.000000 | 60284.000000 | 60284.000000 |
| mean | 6.277615e-01 | 2.234403 | 12.755459 | 2.649437 |
| std | 3.385316e-01 | 1.999493 | 40.180625 | 2.395003 |
| min | 2.670516e-08 | 0.000000 | 0.000000 | 0.000000 |
| 25% | 3.345064e-01 | 0.953863 | 1.235364 | 1.111469 |
| 50% | 7.446224e-01 | 1.789659 | 4.366453 | 2.089606 |
| 75% | 9.337973e-01 | 2.931538 | 12.176169 | 3.489437 |
| max | 1.000000e+00 | 28.657652 | 1349.487919 | 36.735377 |
In [30]:
gpd.GeoSeries(results.linear_model_point).distance(gpd.GeoSeries(results.Sunamura_model_point)).describe()
Out[30]:
count 657.000000 mean 10.961338 std 0.009703 min 10.924303 25% 10.957830 50% 10.964826 75% 10.967859 max 10.972655 dtype: float64
In [31]:
results.set_geometry(f"linear_model_point", inplace=True, crs=2193)
poly = prediction_results_to_polygon(results)
In [32]:
poly.explore(tiles="Esri.WorldImagery")
Out[32]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [33]:
site = df.match.sample(1).iloc[0]
site = "CapeEgmont"
print(site)
gdf = gpd.read_file(f"Shapefiles/{site}_intersects.shp")
gdf.crs = 2193
gdf = enrich_df(gdf)
transect_metadata = get_transect_metadata(f"Shapefiles/{site}_TransectLines.shp")
m = gpd.read_file(f"Shapefiles/{site}_TransectLines.shp").explore("TransectID", tiles="Esri.WorldImagery", max_zoom=22)
linear_models = fit(gdf, transect_metadata)
linear_models.loc[linear_models.slope > 0, "slope"] = pd.NA
rolled_slopes = linear_models.groupby("group").slope.rolling(10, min_periods=1).mean().dropna().reset_index(level=0)
linear_models.slope = rolled_slopes.slope
linear_models.dropna(inplace=True)
results = predict(gdf, linear_models, transect_metadata)
results["geometry"] = results["linear_model_point"]
pd.concat([gdf, results])[["Year", "geometry"]].explore("Year", m=m)
gpd.GeoSeries(results.ocean_point, crs=2193).explore(m=m, color="blue")
#gpd.GeoSeries(poly, crs=2193).explore(color="pink", m=m)
results.set_geometry(f"linear_model_point", inplace=True, crs=2193)
polygon = prediction_results_to_polygon(results)
polygon.boundary.explore(m=m)
m
CapeEgmont
/tmp/ipykernel_19942/2537168661.py:15: FutureWarning: You are adding a column named 'geometry' to a GeoDataFrame constructed without an active geometry column. Currently, this automatically sets the active geometry column to 'geometry' but in the future that will no longer happen. Instead, either provide geometry to the GeoDataFrame constructor (GeoDataFrame(... geometry=GeoSeries()) or use `set_geometry('geometry')` to explicitly set the active geometry column.
results["geometry"] = results["linear_model_point"]
Out[33]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [34]:
run_all_parallel()
0%| | 0/24 [00:00<?, ?it/s]
/home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning)
Flipping
/home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning) /home/nyou045/.local/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples. warnings.warn(msg, UndefinedMetricWarning)
In [35]:
def read_file(f):
df = gpd.read_file(f)
df["filename"] = f
return df
samples = pd.concat(read_file(f) for f in glob("Projected_Shoreline_Polygons/*.shp"))
samples.explore("filename", tiles="Esri.WorldImagery", style_kwds={"fill": False})
Out[35]:
Make this Notebook Trusted to load map: File -> Trust Notebook